package com.quotes.ui;

import java.awt.*;
import javax.swing.*;

public class LoggingPanel extends JPanel implements LoggingTarget
{
	private static final long serialVersionUID = 1L;
	private JTextArea field;
	
	public LoggingPanel() {
		setLayout(new GridBagLayout());
		final GridBagConstraints gc = new GridBagConstraints();
		field = new JTextArea();
		field.setEditable(false);
		JScrollPane scrollPane = new JScrollPane(field);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		gc.weightx = 1d;
		gc.weighty = 1d;
		gc.fill = GridBagConstraints.BOTH;
		this.add(scrollPane, gc);
	}
	
	@Override
	public void append(String text) {
		field.setText(text + "\n" + field.getText());
	}
	
	public void clear() {
		field.setText("");
	}
}
